#include "scheduler.h"

typedef struct 
{
    void (*task_fun)(void);
    uint32_t task_rate;
    uint32_t task_run_old;
}task_t;

static task_t task_scheduler[] = {
    {led_proc, 1, 0},
    {Key_proc, 10, 0},
    {lcd_proc, 100, 0},
    {UART_proc, 50, 0},
    {tim_proc, 20, 0},
	{adc_proc,10,0}
};

uint8_t task_num;
void scheduler_init(void)
{
    task_num = sizeof(task_scheduler) / sizeof(task_t);
}

void scheduler_run(void)
{

    for (uint8_t i = 0; i < task_num;i++)
    {
        uint32_t Now_tim = HAL_GetTick();
        if (Now_tim >= task_scheduler[i].task_rate + task_scheduler[i].task_run_old)
        {
            task_scheduler[i].task_run_old = Now_tim;
            task_scheduler[i].task_fun();
        }
    }
}
